package cn.com.b2office.struts2.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import cn.com.b2office.domain.Cart;
import cn.com.b2office.domain.DeliveryMode;
import cn.com.b2office.domain.MemberAddress;
import cn.com.b2office.domain.Order;
import cn.com.b2office.domain.PaymentMode;
import cn.com.b2office.service.DeliveryService;
import cn.com.b2office.service.MemberService;
import cn.com.b2office.service.OrderCustomService;
import cn.com.b2office.service.OrderService;

import com.opensymphony.xwork2.ActionSupport;

public class PreviewOrderAction extends ActionSupport implements SessionAware {

	private static final long serialVersionUID = 3396473879807881519L;

	private OrderService orderService = null;

	private MemberService memberService = null;

	private DeliveryService deliveryService = null;

	private OrderCustomService orderCustomService = null;

	private Map session = null;

	private List<Order> orders = null;

	private MemberAddress address = null;

	private String addressText = null;

	private DeliveryMode deliveryMode = null;

	private PaymentMode paymentMode = null;

	public String execute() throws Exception {
		Cart cart = (Cart) session.get("cart");
		if (cart == null)
			return "empty";
		orders = orderService.buildOrders(cart);
		if (cart.getAddressId() != null
				|| !cart.getAddressId().trim().equals(""))
			address = memberService.getMemberAddress(cart.getAddressId());
		if (address != null)
			addressText = memberService.translateAddress(address);

		deliveryMode = deliveryService.getDeliveryMode(cart.getDeliveryMode());

		paymentMode = orderCustomService.getPaymentMode(cart.getPayMode());

		return SUCCESS;
	}

	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public List<Order> getOrders() {
		return orders;
	}

	public MemberAddress getAddress() {
		return address;
	}

	public String getAddressText() {
		return addressText;
	}

	public DeliveryMode getDeliveryMode() {
		return deliveryMode;
	}

	public PaymentMode getPaymentMode() {
		return paymentMode;
	}

	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}

	public void setDeliveryService(DeliveryService deliveryService) {
		this.deliveryService = deliveryService;
	}

	public void setOrderCustomService(OrderCustomService orderCustomService) {
		this.orderCustomService = orderCustomService;
	}

}
